package com.morven.workpiece.web.controller.craft;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.morven.workpiece.common.annotation.Log;
import com.morven.workpiece.common.core.controller.BaseController;
import com.morven.workpiece.common.core.domain.AjaxResult;
import com.morven.workpiece.common.core.page.TableDataInfo;
import com.morven.workpiece.common.enums.BusinessType;
import com.morven.workpiece.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.morven.workpiece.craft.domain.CraftProceWageCoeffic;
import com.morven.workpiece.craft.service.ICraftProceWageCoefficService;

/**
 * 工序工价系数Controller
 *
 * @author Morven
 * @date 2021-12-20
 */
@RestController
@RequestMapping("/craft/coeffic")
public class CraftProceWageCoefficController extends BaseController {
    @Autowired
    private ICraftProceWageCoefficService craftProceWageCoefficService;

    /**
     * 查询工序工价系数列表
     */
    @PreAuthorize("@ss.hasPermi('craft:coeffic:list')")
    @GetMapping("/list")
    public TableDataInfo list(CraftProceWageCoeffic craftProceWageCoeffic) {
        startPage();
        List<CraftProceWageCoeffic> list = craftProceWageCoefficService.selectCraftProceWageCoefficList(craftProceWageCoeffic);
        return getDataTable(list);
    }

    /**
     * 导出工序工价系数列表
     */
    @PreAuthorize("@ss.hasPermi('craft:coeffic:export')")
    @Log(title = "工序工价系数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CraftProceWageCoeffic craftProceWageCoeffic) {
        List<CraftProceWageCoeffic> list = craftProceWageCoefficService.selectCraftProceWageCoefficList(craftProceWageCoeffic);
        ExcelUtil<CraftProceWageCoeffic> util = new ExcelUtil<CraftProceWageCoeffic>(CraftProceWageCoeffic.class);
        util.exportExcel(response, list, "工序工价系数数据");
    }

    /**
     * 获取工序工价系数详细信息
     */
    @PreAuthorize("@ss.hasPermi('craft:coeffic:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(craftProceWageCoefficService.selectCraftProceWageCoefficById(id));
    }

    /**
     * 新增工序工价系数
     */
    @PreAuthorize("@ss.hasPermi('craft:coeffic:add')")
    @Log(title = "工序工价系数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CraftProceWageCoeffic craftProceWageCoeffic) {
        craftProceWageCoeffic.setCreateUserId(getUserId());
        craftProceWageCoeffic.setOpUserId(getUserId());
        return toAjax(craftProceWageCoefficService.insertCraftProceWageCoeffic(craftProceWageCoeffic));
    }

    /**
     * 修改工序工价系数
     */
    @PreAuthorize("@ss.hasPermi('craft:coeffic:edit')")
    @Log(title = "工序工价系数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CraftProceWageCoeffic craftProceWageCoeffic) {
        craftProceWageCoeffic.setOpUserId(getUserId());
        return toAjax(craftProceWageCoefficService.updateCraftProceWageCoeffic(craftProceWageCoeffic));
    }

    /**
     * 删除工序工价系数
     */
    @PreAuthorize("@ss.hasPermi('craft:coeffic:remove')")
    @Log(title = "工序工价系数", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(craftProceWageCoefficService.deleteCraftProceWageCoefficByIds(ids));
    }

    /**
     * 初始加载工序系数需要的数据
     * 如：工序类别 categoryList
     *    标准工序单价 standardProcessPirce
     *    工序排序字段信息  processOrderBy
     */
    @GetMapping("/initCoefficData")
    public AjaxResult initCoefficData() {
        return AjaxResult.success(craftProceWageCoefficService.initCoefficData());
    }

}
